package cc.rengu.igas.route.common.dao.impl;

import cc.rengu.igas.route.common.dao.RoutePayOrderMapper;
import cc.rengu.oltp.service.common.constant.AppConfigConstant;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.common.entity.PayOrderInfo;
import cc.rengu.oltp.utility.util.DbsUtil;
import cc.rengu.oltp.utility.util.XmlConfigUtil;
import cc.rengu.oltp.utility.util.XmlTreeUtil;
import cc.rengu.utility.cache.UnifiedCache;
import cc.rengu.utility.log.RgLog;
import cc.rengu.utility.log.RgLogger;

/**
 * 智能路由动态数据统计表操作类
 *
 * @author xlz
 * @version 1.0
 * @date 2020-03-13
 */
public class RoutePayOrderMapperImpl implements RoutePayOrderMapper {
    private RgLogger rglog = RgLog.getLogger(this.getClass().getName());
    private String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.DATABASE_CONF_NODE, AppConfigConstant.ROUTE_POOL_NAME);

    public RoutePayOrderMapperImpl() throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.ROUTE_POOL_NAME);
        }
    }


    @Override
    public int updatePayOrderSettleDate(PayOrderInfo payOrderInfo, String settleDate) throws Exception {
        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "routeUpdatePayOrderSettleDateByPrimaryKey");
        payOrderInfo.setSettleDate(settleDate);
        int iReturnCode = dbsUtil.dbsExecuteSql(sqlStr, payOrderInfo, null);
        if (0 != iReturnCode) {
            rglog.error("根据主键更新支付订单清算日期失败,instId:<{}>,sysSeqNum:<{}>,msgDstId:<{}>,dstCallIndex:<{}>,iReturnCode:<{}>",
                    payOrderInfo.getInstId(), payOrderInfo.getSysSeqNum(), payOrderInfo.getMsgDstId(), payOrderInfo.getDstCallIndex(), iReturnCode);
        }
        return iReturnCode;
    }
}
